<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<style type="text/css">
#edit_goods_type_info .box label span {
	display: inline-block;
	width: 74px;
	text-align: right;
}

#edit_goods_type_info .box label {
	margin-left: 20px;
}

#edit_goods_type_info .formBox {
	padding: 0;
	position: relative;
}

#edit_goods_type_info .formBox>div {
	padding: 20px;
}

#edit_goods_type_info .updateBox label span {
	width: 96px;
}
</style>
<div class="modal fade" id="edit_goods_type_info" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document" style="width: 360px;">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">编辑物品分类</h4>
			</div>
			<form id="edit_goods_type_form" class="form">
				<input type="hidden" name="categoryid" id="categoryid">
				<div class="box modal-body">
					<p>
						<label>类别编码</label>
						<input type="text" class="form-control" id="categorycode" readonly >
					</p>
					<p>
						<label>类别名称</label>
						<input type="text" class="form-control" id="categoryname" name="categoryname"></input>
					</p>
					<p>
						<label>类别备注</label>
						<input type="text" class="form-control" id="description" name="description"></input>
					</p>
					<p>
						<label>创建人</label>
						<input type="text" class="form-control" id="createpersonname"></input>
					</p>
					<p>
						<label>创建时间</label>
						<input type="text" class="form-control" id="createtime"></input>
					</p>
				</div>
			</form>
			<div class="red" id="edit_goods_type_msg" style="text-align:center;"></div>
			<div class="modal-footer">
				<c:if test="${isEdit }">
					<button type="button" class="btn btn1" onclick="saveEditGoodsType();">保存</button>
				</c:if>
				<button type="button" class="btn btn2" data-dismiss="modal">取消</button>
			</div>
		</div>
	</div>
</div>
<script>

function editGoodsType(id){
	$('#edit_goods_type_info :text').val("");
	$("#edit_goods_type_info :hidden").val("");
	$.ajax({
		url:"<%=basePath %>category/findCategoryById.do",
		type:"post",
		async : false,
		dataType:"json",
		data:"categoryid="+id,
		success:function(data){
			$("#edit_goods_type_info #categoryid").val(categoryid);
			$("#edit_goods_type_info #categorycode").val(data.categorycode);
			$("#edit_goods_type_info #categoryname").val(data.categoryname);
			$("#edit_goods_type_info #description").val(data.description);
			var date=new Date();
			date.setTime(data.createtime);
			$("#edit_goods_type_info #createtime").val(date.format('yyyy-MM-dd HH:mm:ss'));
			$("#edit_goods_type_info #createpersonname").val(data.name);
		}
	});
	$('#edit_goods_type_info').modal('show');
}

function saveEditGoodsType(){
	if(!validateEditForm()) return ;
	$.ajax({
		url:"<%=basePath %>category/update.do",
		type:"post",
		async : false,
		dataType:"json",
		data : $("#edit_goods_type_form").serialize(),
		success:function(data){
			if(data.result=="success"){
				$("#edit_goods_type_msg").html("");
				$('#edit_goods_type_info :text').val("");
				$("#edit_goods_type_info :hidden").val("");
				$("#edit_goods_type_info #categoryid").val("");
				$('#edit_goods_type_info').modal('hide');
				location.href=location.href;
			}else{
				Prompt.alert("提示：","修改物品分类失败："+data.error);
			}
		},
		error :function(){
			Prompt.alert("提示：","修改物品分类失败！");
		}
	});
}

function validateEditForm(){
 	if(!validateString("类别名称","#edit_goods_type_form [name='categoryname']",30,false)){
		return false;
	}
	if(!validateString("类别备注","#edit_goods_type_form [name='description']",120,true)){
		return false;
	}
	return true;
}
</script>